const Sequelize = require('sequelize')
const { database, server } = require('../config')

const {
  dbName, user, password, host, port
} = database;

const sequelize = new Sequelize(dbName, user, password, {
  dialect: 'mysql',
  host,
  port,
  logging: false,
  timezone: '+08:00',
  define: {
    // create_time && update_time
    timestamps: true,
    // delete_time
    paranoid: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    deletedAt: 'deleted_at',
    // 把驼峰命名转换为下划线
    underscored: true,
  }
})
// 创建模型
let isDev = server.environment === 'dev';
sequelize.sync({ force: false })
module.exports = {
  sequelize
}